#! /bin/sh
# shellcheck disable=all
# Serene Programming Language
#
# Copyright (c) 2019-2024 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# -----------------------------------------------------------------------------
# Commentary
# -----------------------------------------------------------------------------
# This is the builder script for the Serene project. It makes it easier to
# interact with the CMake build scripts.
#
# In order to define a subcommand all you need to do is to define a function
# with the following syntax:
#
# function subcommand-name() { ## DESCRIPTION
#   .. subcommand body ..
# }
#
# Make sure to provid one line of DESCRIPTION for the subcommand and use two "#"
# characters to start the description following by a space. Otherwise, your
# subcommand won't be registered
#


# shellcheck source=./utils.sh
source "$ME/scripts/utils.sh"



function build-pdf() { ## Build the give tex file as pdf
    rm -rf "$BUILD_DIR/maths/"
    mkdir -p "$BUILD_DIR/maths/"
    latexmk -f -xelatex -interaction=nonstopmode -output-directory="$BUILD_DIR/maths/" "$1"
}

function help() { ## Print out this help message
    echo "Commands:"
    grep -E '^function [a-zA-Z0-9_-]+\(\) \{ ## .*$$' "$ME/scripts/mathfunctions.sh" | \
        sort | \
        sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1:\2/' | \
        awk 'BEGIN {FS=":"}; {printf "\033[36m%-30s\033[0m %s\n", $1, $2}'
}
